/**
* File name : Timer.cpp
* Location  : /Core/
* Lib. name : Core
* Designer  : Riza
* Mod 1. by :
* Mod 2. by :
*/

#include "stdafx.h"
#include "Timer.h"
#include "System.h"

namespace Core
{
	Timer::~Timer()
	{
		m_Interval = 10000;
	}

	void Timer::Execute()
	{
		while(true)
		{
			m_TimeSpan.Tick();
			ExecuteByInterval();
			float t_Delta = m_TimeSpan.Tick()*1000;
			t_Delta = m_Interval-t_Delta;
			if(t_Delta>0)
			{
				System::MilliSleep((unsigned short)t_Delta);
			}
		}
	}

	void Timer::TryExecute()
	{
		float t_Delta = m_TimeSpan.Peek()*1000;
		if(t_Delta>m_Interval)
		{
			ExecuteByInterval();
			m_TimeSpan.Tick();
		}
	}

	void Timer::Start(unsigned long p_Interval)
	{
		SetInterval(p_Interval);
		Thread::Start();
	}

	unsigned long Timer::GetInterval()
	{
		return m_Interval;
	}

	void Timer::SetInterval(unsigned long p_Interval)
	{
		m_Interval = p_Interval;
	}
}
